﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UFSSClientClasses;

namespace UFSSDesktopApp
{
    public partial class FormLogin : Form
    {
        UFSSservicereference.UserCreds uc = new UFSSservicereference.UserCreds();
        UFSSservicereference.UFSSserviceSoapClient ussc;

        public FormLogin(UFSSservicereference.UFSSserviceSoapClient sc)
        {
            InitializeComponent();
            ussc = sc;
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            uc.Username = txtUsername.Text;
            uc.Password = txtPassword.Text;
            if(this.ussc.State == System.ServiceModel.CommunicationState.Opened)
            {
                lblStatus.Text = "Attempting to log in";
            }
            if (ussc.LoginUser(ref uc))
            {
                FormMain fm = new FormMain(ussc, uc);
                
                FormLogin.ActiveForm.Hide();
                fm.Show();
                
            }
            else
            {
                lblStatus.Text = "Login failed!";
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}

